<template>
  <div>
    <Row class="search-info-style">
      <Col span="6">
        <span>机构编码：</span>
        <Input v-model="searchInfo.code" placeholder="印章编码" style="width:70%" />
      </Col>
      <Col span="6">
        <Button type="primary" size="default" style="margin-right: 5px" @click="changePageNo(1)">搜索</Button>
      </Col>
    </Row>
    <Table border :columns="columns" :data="dataList">
      <template #action="{ row }">
        <Button type="primary" size="small" style="margin-right: 5px" @click="updateInfo(row)">编辑</Button>
      </template>
    </Table>
    <Page class="page_style" :total="searchInfo.totalnum" :current="searchInfo.currentPageNo"
          :page-size="searchInfo.currentPageSize" @on-change="changePageNo" show-total  show-sizer @on-page-size-change="size"/>

    <Modal
      title="电子印章配置"
      v-model="show"
      @on-cancel="show === false"
      @on-ok="updateOk">
      <div style="text-align: center">
        <Row class="search-info-style">
          <Col span="12">
            <span>印章编码：</span>
            <Input v-model="paramData.yzbm" placeholder="印章编码" style="width:70%" />
          </Col>
        </Row>
      </div>
    </Modal>
  </div>
</template>
<script>
import { findDzyzList, saveDzyz } from '@/api/eventlist'
export default {
  data () {
    return {
      show: false,
      paramData: {},
      searchInfo: {
        totalnum: 0,
        currentPageNo: 1,
        currentPageSize: 10,
        code: ''
      },
      columns: [
        { title: '序号', type: 'index', key: 'index', width: 100, align: 'center' },
        { title: '机构名称', key: 'name', align: 'center' },
        { title: '机构编码', key: 'code', align: 'center' },
        { title: '印章编码', key: 'yzbm', align: 'center' },
        { title: '操作', slot: 'action', width: 200, align: 'center' }
      ],
      dataList: []
    }
  },
  methods: {
    init () {
      let param = {
        pageNo: this.searchInfo.currentPageNo,
        pageSize: this.searchInfo.currentPageSize,
        code: this.searchInfo.code
      }
      findDzyzList(param).then(res => {
        if (res.data.errcode === 0) {
          this.dataList = res.data.data.results
          this.searchInfo.totalnum = res.data.data.totalRecord
        } else {
          this.$Notice.error({ title: '获取列表失败', desc: res.data.errmsg })
        }
      })
    },
    size (pageSize) {
      this.searchInfo.currentPageSize = pageSize
      this.changePageNo(1)
    },
    changePageNo (pageNo) {
      this.searchInfo.currentPageNo = pageNo
      this.init()
    },
    updateInfo (item) {
      this.paramData = this.$common.xeUtils.clone(item, true)
      this.show = true
    },
    updateOk () {
      saveDzyz(this.paramData).then(res => {
        if (res.data.errcode === 0) {
          this.$Notice.success({ title: '操作完成', desc: '' })
          this.changePageNo(1)
        } else {
          this.$Notice.error({ title: '操作失败', desc: res.data.errmsg })
        }
      })
    }
  },
  mounted () {
    this.init()
  }
}
</script>
<style>
.page_style {
  margin-top: 10px;
  text-align: right;
}
.search-info-style {
  margin: 10px;
}
</style>
